package classes;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * Data access object (DAO) for domain model class Contrat.
 * 
 * @see classes.Contrat
 * @author MyEclipse Persistence Tools
 */

public class ContratDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(ContratDAO.class);

	// property constants
	public static final String NOM_METIER = "nomMetier";

	public static final String SALAIRE_HORAIRE = "salaireHoraire";

	public void save(Contrat transientInstance) {
		log.debug("saving Contrat instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Contrat persistentInstance) {
		log.debug("deleting Contrat instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Contrat findById(java.lang.Integer id) {
		log.debug("getting Contrat instance with id: " + id);
		try {
			Contrat instance = (Contrat) getSession()
					.get("classes.Contrat", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Contrat instance) {
		log.debug("finding Contrat instance by example");
		try {
			List results = getSession().createCriteria("classes.Contrat").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Contrat instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Contrat as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByNomMetier(Object nomMetier) {
		return findByProperty(NOM_METIER, nomMetier);
	}

	public List findBySalaireHoraire(Object salaireHoraire) {
		return findByProperty(SALAIRE_HORAIRE, salaireHoraire);
	}

	public List findAll() {
		log.debug("finding all Contrat instances");
		try {
			String queryString = "from Contrat";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Contrat merge(Contrat detachedInstance) {
		log.debug("merging Contrat instance");
		try {
			Contrat result = (Contrat) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Contrat instance) {
		log.debug("attaching dirty Contrat instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Contrat instance) {
		log.debug("attaching clean Contrat instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}